package com.boniu.startapp.services;

import android.accessibilityservice.AccessibilityService;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.util.Log;
import android.view.accessibility.AccessibilityEvent;

import com.boniu.startapp.Config;
import com.boniu.startapp.SPUtils;

import java.util.Date;


public class AdMainFunctions {
    public static final String TAG = "MyAccessibilityService";
    private AccessibilityService service;
    private boolean nightOpen = true;//下班打卡
    private boolean dayOpen = true;//上班打卡
    private boolean isLock = false;//是否锁屏

    public void setLock(boolean lock) {
        isLock = lock;
    }

    public AdMainFunctions(AccessibilityService service) {
        this.service = service;
    }

    public void onServiceConnected() {
        LockScreenBroadcastReceiver.register(service);
//        NotificationEventReceiver.register(service);
    }

    public void onAccessibilityEvent(AccessibilityEvent event) {
        String appPacName = event.getPackageName().toString();
        if (!isLock){
            Date date = new Date();
            int hours = date.getHours();
            int minutes = date.getMinutes();
            if (hours == 9 && minutes > 20 && dayOpen){
                startDD(true);
            }
            if (hours == 18 && minutes >= 36 && nightOpen){
                startDD(false);
            }
            if (hours > 18 && nightOpen){
                startDD(false);
            }
//            Log.e("asd", "onReceive:ACTION_TIME_TICK " + hours + ":" + minutes + ":" + dayOpen + ":" + nightOpen );

        }


    }
    private void startDD(boolean isDay){
        PackageManager packageManager = service.getPackageManager();
        Intent intent=new Intent();
        intent =packageManager.getLaunchIntentForPackage("com.alibaba.android.rimet");
        if (intent != null){
            if (isDay){
                nightOpen = true;
                dayOpen = false;
            }else{
                dayOpen = true;
                nightOpen = false;
            }
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            service.startActivity(intent);
        }else{
            Log.e("asd", "onAccessibilityEvent: " );
        }
    }


}
